"use strict";

const Constant = require("../basics/constant");
const Result = require("../basics/result");
const BaseImpl = require("../basics/clz/baseimpl");
const BeneiftUtil = require("../taobao/beneift");
const TicketModel = require("../model/ticket");

/**
 * 通用服务
 */
class HomeImpl extends BaseImpl {

  /**
   * 奖品列表
   */
  async findList() {
    return await TicketModel.getInstant(this.cloud).selectList();
  }
  /**
   * 绑定商品
   * @param {*} params 
   */
  async edit(params) {
    const { id, code, name } = params;
    const ticketModel = TicketModel.getInstant(this.cloud);
    if (!id) {
      const ticket = await ticketModel.selectOneByCode(code);
      if (ticket) {
        throw Result.error(Result.constant.fail, "请勿重复添加");
      }
      await ticketModel.insertOne({ code, name: "" });
    } else {
      await ticketModel.updateById({ name }, id);
    }
    return true;
  }
}

module.exports = HomeImpl;